import toolMgr from '@/biz/base/tool.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        title: '内容',
        field: 'content',
        minWidth: 180,
        align: 'center'
      },
      {
        field: 'buAttaches',
        title: '附件',
        minWidth: 160,
        cell: (item) => {
          return {
            edit: {
              tag: {
                type: 'text',
                options: item.buAttaches?.map((i) => ({
                  key: i.attachAddress,
                  value: i.fileName
                })),
                style: {
                  display: 'block'
                },
                click: (tag) => {
                  toolMgr.downloadFile(tag.key, tag.value)
                }
              }
            }
          }
        }
      },
      {
        title: '操作',
        fixed: 'right',
        width: 140,
        align: 'center',
        cell: (item) => {
          let btn = []
          btn.push({
            title: '编辑',
            event: 'edit',
            code: '0102011102'
          })
          btn.push({
            title: '删除',
            event: 'remove',
            code: '0102011103'
          })
          return {
            btn
          }
        }
      }
    ]
  }
}

export default Column
